import fs from 'fs'
import path from 'path'

function copyBootstrapIconsCss() {
    const sourceName = './node_modules/bootstrap-icons/font/bootstrap-icons.min.css'
    const sourceText = fs.readFileSync(sourceName, { encoding: 'utf-8' })
    const targetText = sourceText.replace(
        /(url\(\")fonts(\/bootstrap\-icons\.woff2?)\?.+?(\"\))/g,
        '$1https://file.dogzhang.com/bootstrap-icons/fonts$2$3',
    )
    const targetName = './static/fonts/bootstrap-icons.min.css'
    const targetDirName = path.dirname(targetName)
    if (!fs.existsSync(targetDirName)) {
        fs.mkdirSync(targetDirName, { recursive: true })
    }
    fs.writeFileSync(targetName, targetText)
}

function go() {
    copyBootstrapIconsCss()
}

go()
